package com.suliao.home.serviceImpl.content;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suliao.common.util.OSSUtil;
import com.suliao.home.entity.content.InformationDO;
import com.suliao.home.entity.content.InformationTypeDO;
import com.suliao.home.entity.sys.FileDO;
import com.suliao.home.mapper.content.InformationMapper;
import com.suliao.home.mapper.sys.FileMapper;
import com.suliao.home.service.content.InformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author： M1nG-CodeGenerator
 * @since： 2020-12-12 11:33:58
 * @description： 资讯栏目表 服务实现类
 * @version： 1.0
 */
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, InformationDO> implements InformationService {

    @Autowired
    private InformationMapper informationMapper;

    @Autowired
    private FileMapper fileMapper;

    /**
     * 查看产业资讯+1
     *
     * @param id
     * @return
     */
    @Override
    public Integer updateIndustryInfoHits(Integer id) {
        return informationMapper.updateIndustryInfoHits(id);
    }

    /**
     * 产业资讯点赞量更新
     *
     * @param id
     * @param number
     * @return
     */
    @Override
    public Integer updateLikeNum(Integer id, Integer number) {
        return informationMapper.updateLikeNum(id, number);
    }

    /**
     * 页面加载的时候获得默认的产业资讯列表，默认选中推荐按钮
     *
     * @param pageInfo
     * @param id
     * @return
     */
    @Override
    public Page<InformationDO> loadIndustryInfoList(Page pageInfo, Integer id) {
        Page<InformationDO> industryInfoList = informationMapper.loadIndustryInfoList(pageInfo, id);
        for (int i = 0; i < industryInfoList.getRecords().size(); i++) {
            String coverImgFileId = industryInfoList.getRecords().get(i).getCoverImgFileId();
            //从文件表中查询封面图片URL,修改大小后放到资讯表的URL字段中
            FileDO fileDo = fileMapper.getFileUrl(coverImgFileId);
            if (fileDo != null) {
                String fileUrl = OSSUtil.getUrlByResize(fileDo.getFileUrl(), 60, 60);
                industryInfoList.getRecords().get(i).setCoverImgFileUrl(fileUrl);
            }
        }
        return industryInfoList;
    }

    /**
     * 通过产业资讯的所属栏目类别ID，去查询资讯列表信息
     * @param id
     * @return
     */
    @Override
    public List<InformationDO> queryInfoByTypeId(Integer id) {
        return informationMapper.queryInfoByTypeId(id);
    }

    /**
     * 通过id查询产业资讯
     * @param id
     * @return
     */
    @Override
    public InformationDO getIndustryInfoById(Integer id) {
        return informationMapper.getIndustryInfoById(id);
    }

}
